﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Qplus.UI
{
    public partial class TestControl : UserControl
    {
        public TestControl()
        {
            InitializeComponent();
        }
        private Duration duration = new Duration(TimeSpan.FromSeconds(1));
        private ImageSource tempSource = null;
        /// <summary>
        /// Is the animation running
        /// </summary>
        public bool IsRunning = false;
        private ScaleType scaleType = ScaleType.Direct;

        /// <summary>
        /// Animate type during scale
        /// </summary>
        public ScaleType ScaleAnimateType
        {
            get
            {
                return this.scaleType;
            }
            set
            {
                this.scaleType = value;
            }
        }

        private RotateType rotateType = RotateType.Direct;

        /// <summary>
        /// Animate type during rotate
        /// </summary>
        public RotateType RotateAnimateType
        {
            get
            {
                return this.rotateType;
            }
            set
            {
                this.rotateType = value;
            }
        }

        /// <summary>
        /// Duration of animate
        /// </summary>
        public double AnimateDuration
        {
            get
            {
                return duration.TimeSpan.TotalSeconds;
            }
            set
            {
                duration = new Duration(TimeSpan.FromSeconds(value));
            }
        }


        /// <summary>
        /// Set current image
        /// </summary>
        /// <param name="imgSource">image source</param>
        public void SetImage(ImageSource imgSource)
        {
            this.imageMain.Source = imgSource;
            if (this.LayoutRoot.Children.Count > 1)
            {
                this.LayoutRoot.Children.RemoveAt(1);
            }
        }

        /// <summary>
        /// Set current image with a switch animation
        /// </summary>
        /// <param name="imgSource">Image source</param>
        /// <param name="switchType">Switch type</param>
        public void SetImage(ImageSource imgSource, SwitchType switchType)
        {
            StopAllStoryBoard();
            this.tempSource = imgSource;
            if (switchType == SwitchType.Random)
            {
                Random r = new Random();
                //TODO: 增加了效果后也要注意修改这里
                int i = r.Next(1, 34);
                switchType = (SwitchType)i;
            }

            //TODO: 如果添加了效果，应该注意修改这个值
            if ((int)switchType > 18)  // 都是飞出效果
            {
                InitTempImage(this.imageMain.Source);
                this.imageMain.Source = imgSource;
            }
            else   //飞入效果
            {
                InitTempImage(imgSource);
            }

            this.IsRunning = true;

            switch (switchType)
            {
                case SwitchType.FadeIn:
                    PlayFadeIn();
                    break;
                case SwitchType.FlyFromLeft:
                    PlayFly(FlyDirection.FromLeft);
                    break;
                case SwitchType.FlyFromRight:
                    PlayFly(FlyDirection.FromRight);
                    break;
                case SwitchType.FlyFromTop:
                    PlayFly(FlyDirection.FromTop);
                    break;
                case SwitchType.FlyFromBottom:
                    PlayFly(FlyDirection.FromBottom);
                    break;
                case SwitchType.ScaleFromCenter:
                    PlayScale(ScaleDirection.FromCenter);
                    break;
                case SwitchType.ScaleFromUpperLeft:
                    PlayScale(ScaleDirection.FromUpperLeft);
                    break;
                case SwitchType.ScaleFromUpperRight:
                    PlayScale(ScaleDirection.FromUpperRight);
                    break;
                case SwitchType.ScaleFromBottomLeft:
                    PlayScale(ScaleDirection.FromBottomLeft);
                    break;
                case SwitchType.ScaleFromBottomRight:
                    PlayScale(ScaleDirection.FromBottomRight);
                    break;
                case SwitchType.RotateInFromBottomToLeft:
                    PlayRotate(RotateDirection.EnterFromBottomToLeft);
                    break;
                case SwitchType.RotateInFromBottomToRight:
                    PlayRotate(RotateDirection.EnterFromBottomToRight);
                    break;
                case SwitchType.RotateInFromLeftToBottom:
                    PlayRotate(RotateDirection.EnterFromLeftToBottom);
                    break;
                case SwitchType.RotateInFromLeftToTop:
                    PlayRotate(RotateDirection.EnterFromLeftToTop);
                    break;
                case SwitchType.RotateInFromRightToBottom:
                    PlayRotate(RotateDirection.EnterFromRightToBottom);
                    break;
                case SwitchType.RotateInFromRightToTop:
                    PlayRotate(RotateDirection.EnterFromRightToTop);
                    break;
                case SwitchType.RotateInFromTopToLeft:
                    PlayRotate(RotateDirection.EnterFromTopToLeft);
                    break;
                case SwitchType.RotateInFromTopToRight:
                    PlayRotate(RotateDirection.EnterFromTopToRight);
                    break;
                case SwitchType.FlyToLeft:
                    PlayFly(FlyDirection.ToLeft);
                    break;
                case SwitchType.FlyToRight:
                    PlayFly(FlyDirection.ToRight);
                    break;
                case SwitchType.FlyToTop:
                    PlayFly(FlyDirection.ToTop);
                    break;
                case SwitchType.FlyToBottom:
                    PlayFly(FlyDirection.ToBottom);
                    break;
                case SwitchType.ScaleToUpperLeft:
                    PlayScale(ScaleDirection.ToUpperLeft);
                    break;
                case SwitchType.ScaleToUpperRight:
                    PlayScale(ScaleDirection.ToUpperRight);
                    break;
                case SwitchType.ScaleToBottomLeft:
                    PlayScale(ScaleDirection.ToBottomLeft);
                    break;
                case SwitchType.ScaleToBottomRight:
                    PlayScale(ScaleDirection.ToBottomRight);
                    break;
                case SwitchType.ScaleToCenter:
                    PlayScale(ScaleDirection.ToCenter);
                    break;
                case SwitchType.RotateOutFromBottomToLeft:
                    PlayRotate(RotateDirection.ExitFromBottomToLeft);
                    break;
                case SwitchType.RotateOutFromBottomToRight:
                    PlayRotate(RotateDirection.ExitFromBottomToRight);
                    break;
                case SwitchType.RotateOutFromLeftToBottom:
                    PlayRotate(RotateDirection.ExitFromLeftToBottom);
                    break;
                case SwitchType.RotateOutFromLeftToTop:
                    PlayRotate(RotateDirection.ExitFromLeftToTop);
                    break;
                case SwitchType.RotateOutFromRightToBottom:
                    PlayRotate(RotateDirection.ExitFromRightToBottom);
                    break;
                case SwitchType.RotateOutFromRightToTop:
                    PlayRotate(RotateDirection.ExitFromRightToTop);
                    break;
                case SwitchType.RotateOutFromTopToLeft:
                    PlayRotate(RotateDirection.ExitFromTopToLeft);
                    break;
                case SwitchType.RotateOutFromTopToRight:
                    PlayRotate(RotateDirection.ExitFromTopToRight);
                    break;
            }
        }

        private void InitTempImage(ImageSource imgSource)
        {
            Image imageTemp = new Image();
            imageTemp.Source = imgSource;
            imageTemp.SetValue(Image.NameProperty, "imageTemp");
            imageTemp.Width = this.Width;
            imageTemp.Height = this.Height;
            imageTemp.Margin = new Thickness(0, 0, 0, 0);
            imageTemp.HorizontalAlignment = HorizontalAlignment.Center;
            imageTemp.VerticalAlignment = VerticalAlignment.Center;
            Color c = Color.FromArgb(255, 0, 0, 0);
            imageTemp.SetValue(Canvas.ZIndexProperty, 1);
            TransformGroup transforms = new TransformGroup();
            CompositeTransform _composite = new CompositeTransform();
            TranslateTransform _translate = new TranslateTransform();
            RotateTransform _rotate = new RotateTransform();
            ScaleTransform _scale = new ScaleTransform();

            transforms.Children.Add(_composite);
            transforms.Children.Add(_translate);
            transforms.Children.Add(_rotate);
            transforms.Children.Add(_scale);
            imageTemp.RenderTransform = transforms;

            BitmapCache bc = new BitmapCache();
            bc.RenderAtScale = 1;
            imageTemp.CacheMode = bc;

            this.LayoutRoot.Children.Add(imageTemp);
        }
        private void PlayScale(ScaleDirection sd)
        {
            DoubleAnimationUsingKeyFrames daukf1 = this.ImageStoryboard_Scale.Children[0] as DoubleAnimationUsingKeyFrames;
            daukf1.KeyFrames[1].KeyTime = this.duration.TimeSpan;
            DoubleAnimationUsingKeyFrames daukf2 = this.ImageStoryboard_Scale.Children[1] as DoubleAnimationUsingKeyFrames;
            daukf2.KeyFrames[1].KeyTime = this.duration.TimeSpan;
            PointAnimationUsingKeyFrames daukf3 = this.ImageStoryboard_Scale.Children[2] as PointAnimationUsingKeyFrames;
            daukf3.KeyFrames[1].KeyTime = this.duration.TimeSpan;
            switch (sd)
            {
                case ScaleDirection.FromUpperLeft:
                    if (this.scaleType == ScaleType.Direct)
                        daukf3.KeyFrames[1].Value = new Point(0, 0);
                    else
                        daukf3.KeyFrames[1].Value = new Point(1, 1);
                    daukf1.KeyFrames[0].Value = 0;
                    daukf1.KeyFrames[1].Value = 1;
                    daukf2.KeyFrames[0].Value = 0;
                    daukf2.KeyFrames[1].Value = 1;
                    daukf3.KeyFrames[0].Value = new Point(0, 0);
                    break;
                case ScaleDirection.FromUpperRight:
                    if (this.scaleType == ScaleType.Direct)
                        daukf3.KeyFrames[1].Value = new Point(1, 0);
                    else
                        daukf3.KeyFrames[1].Value = new Point(0, 1);
                    daukf1.KeyFrames[0].Value = 0;
                    daukf1.KeyFrames[1].Value = 1;
                    daukf2.KeyFrames[0].Value = 0;
                    daukf2.KeyFrames[1].Value = 1;
                    daukf3.KeyFrames[0].Value = new Point(1, 0);
                    break;
                case ScaleDirection.FromBottomLeft:
                    if (this.scaleType == ScaleType.Direct)
                        daukf3.KeyFrames[1].Value = new Point(0, 1);
                    else
                        daukf3.KeyFrames[1].Value = new Point(1, 0);
                    daukf1.KeyFrames[0].Value = 0;
                    daukf1.KeyFrames[1].Value = 1;
                    daukf2.KeyFrames[0].Value = 0;
                    daukf2.KeyFrames[1].Value = 1;
                    daukf3.KeyFrames[0].Value = new Point(0, 1);
                    break;
                case ScaleDirection.FromBottomRight:
                    if (this.scaleType == ScaleType.Direct)
                        daukf3.KeyFrames[1].Value = new Point(1, 1);
                    else
                        daukf3.KeyFrames[1].Value = new Point(0, 0);
                    daukf1.KeyFrames[0].Value = 0;
                    daukf1.KeyFrames[1].Value = 1;
                    daukf2.KeyFrames[0].Value = 0;
                    daukf2.KeyFrames[1].Value = 1;
                    daukf3.KeyFrames[0].Value = new Point(1, 1);
                    break;
                case ScaleDirection.ToUpperLeft:
                    if (this.scaleType == ScaleType.Direct)
                        daukf3.KeyFrames[0].Value = new Point(0, 0);
                    else
                        daukf3.KeyFrames[0].Value = new Point(1, 1);
                    daukf1.KeyFrames[0].Value = 1;
                    daukf1.KeyFrames[1].Value = 0;
                    daukf2.KeyFrames[0].Value = 1;
                    daukf2.KeyFrames[1].Value = 0;
                    daukf3.KeyFrames[1].Value = new Point(0, 0);
                    break;
                case ScaleDirection.ToUpperRight:
                    if (this.scaleType == ScaleType.Direct)
                        daukf3.KeyFrames[0].Value = new Point(1, 0);
                    else
                        daukf3.KeyFrames[0].Value = new Point(0, 1);
                    daukf1.KeyFrames[0].Value = 1;
                    daukf1.KeyFrames[1].Value = 0;
                    daukf2.KeyFrames[0].Value = 1;
                    daukf2.KeyFrames[1].Value = 0;
                    daukf3.KeyFrames[1].Value = new Point(1, 0);
                    break;
                case ScaleDirection.ToBottomLeft:
                    if (this.scaleType == ScaleType.Direct)
                        daukf3.KeyFrames[0].Value = new Point(0, 1);
                    else
                        daukf3.KeyFrames[0].Value = new Point(1, 0);
                    daukf1.KeyFrames[0].Value = 1;
                    daukf1.KeyFrames[1].Value = 0;
                    daukf2.KeyFrames[0].Value = 1;
                    daukf2.KeyFrames[1].Value = 0;
                    daukf3.KeyFrames[1].Value = new Point(0, 1);
                    break;
                case ScaleDirection.ToBottomRight:
                    if (this.scaleType == ScaleType.Direct)
                        daukf3.KeyFrames[0].Value = new Point(1, 1);
                    else
                        daukf3.KeyFrames[0].Value = new Point(0, 0);
                    daukf1.KeyFrames[0].Value = 1;
                    daukf1.KeyFrames[1].Value = 0;
                    daukf2.KeyFrames[0].Value = 1;
                    daukf2.KeyFrames[1].Value = 0;
                    daukf3.KeyFrames[1].Value = new Point(1, 1);
                    break;
                case ScaleDirection.ToCenter:
                    if (this.scaleType == ScaleType.Direct)
                        daukf3.KeyFrames[0].Value = new Point(0.5, 0.5);
                    else
                        daukf3.KeyFrames[0].Value = new Point(0, 0);
                    daukf1.KeyFrames[0].Value = 1;
                    daukf1.KeyFrames[1].Value = 0;
                    daukf2.KeyFrames[0].Value = 1;
                    daukf2.KeyFrames[1].Value = 0;
                    daukf3.KeyFrames[1].Value = new Point(0.5, 0.5);
                    break;
                default: //ScaleFromCenter
                    if (this.scaleType == ScaleType.Direct)
                        daukf3.KeyFrames[1].Value = new Point(0.5, 0.5);
                    else
                        daukf3.KeyFrames[1].Value = new Point(0, 0);
                    daukf1.KeyFrames[0].Value = 0;
                    daukf1.KeyFrames[1].Value = 1;
                    daukf2.KeyFrames[0].Value = 0;
                    daukf2.KeyFrames[1].Value = 1;
                    daukf3.KeyFrames[0].Value = new Point(0.5, 0.5);
                    break;
            }

            this.ImageStoryboard_Scale.Begin();
        }
        private void PlayFly(FlyDirection fid)
        {
            DoubleAnimationUsingKeyFrames daukf = this.ImageStoryboard_Fly.Children[0] as DoubleAnimationUsingKeyFrames;
            PropertyPath pp;
            switch (fid)
            {
                case FlyDirection.FromLeft:
                    pp = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.X)");
                    daukf.SetValue(Storyboard.TargetPropertyProperty, pp);
                    daukf.KeyFrames[0].Value = -this.LayoutRoot.ActualWidth;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case FlyDirection.FromRight:
                    pp = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.X)");
                    daukf.SetValue(Storyboard.TargetPropertyProperty, pp);
                    daukf.KeyFrames[0].Value = this.LayoutRoot.ActualWidth;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case FlyDirection.FromTop:
                    pp = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)");
                    daukf.SetValue(Storyboard.TargetPropertyProperty, pp);
                    daukf.KeyFrames[0].Value = -this.LayoutRoot.ActualHeight;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case FlyDirection.FromBottom:
                    pp = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)");
                    daukf.SetValue(Storyboard.TargetPropertyProperty, pp);
                    daukf.KeyFrames[0].Value = this.LayoutRoot.ActualHeight;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case FlyDirection.ToLeft:
                    pp = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.X)");
                    daukf.SetValue(Storyboard.TargetPropertyProperty, pp);
                    daukf.KeyFrames[0].Value = 0;
                    daukf.KeyFrames[1].Value = -this.LayoutRoot.ActualWidth;
                    break;
                case FlyDirection.ToRight:
                    pp = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.X)");
                    daukf.SetValue(Storyboard.TargetPropertyProperty, pp);
                    daukf.KeyFrames[0].Value = 0;
                    daukf.KeyFrames[1].Value = this.LayoutRoot.ActualWidth;
                    break;
                case FlyDirection.ToTop:
                    pp = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)");
                    daukf.SetValue(Storyboard.TargetPropertyProperty, pp);
                    daukf.KeyFrames[0].Value = 0;
                    daukf.KeyFrames[1].Value = -this.LayoutRoot.ActualHeight;
                    break;
                case FlyDirection.ToBottom:
                    pp = new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)");
                    daukf.SetValue(Storyboard.TargetPropertyProperty, pp);
                    daukf.KeyFrames[0].Value = 0;
                    daukf.KeyFrames[1].Value = this.LayoutRoot.ActualHeight;
                    break;
            }

            daukf.KeyFrames[1].KeyTime = this.duration.TimeSpan;
            this.ImageStoryboard_Fly.Begin();

        }
        private void PlayFadeIn()
        {

            DoubleAnimation da = this.ImageStoryboard_FadeIn.Children[0] as DoubleAnimation;
            da.Duration = this.duration.TimeSpan;
            this.ImageStoryboard_FadeIn.Begin();

        }
        private void PlayRotate(RotateDirection rd)
        {

            PointAnimationUsingKeyFrames paukf = this.ImageStoryboard_Rotate.Children[0] as PointAnimationUsingKeyFrames;
            DoubleAnimationUsingKeyFrames daukf = this.ImageStoryboard_Rotate.Children[1] as DoubleAnimationUsingKeyFrames;
            paukf.KeyFrames[1].KeyTime = this.duration.TimeSpan;
            daukf.KeyFrames[1].KeyTime = this.duration.TimeSpan;
            switch (rd)
            {
                case RotateDirection.EnterFromLeftToTop:
                    paukf.KeyFrames[0].Value = new Point(0, 0);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[1].Value = new Point(0, 0);
                    else
                        paukf.KeyFrames[1].Value = new Point(1, 1);
                    daukf.KeyFrames[0].Value = 90;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case RotateDirection.EnterFromTopToLeft:
                    paukf.KeyFrames[0].Value = new Point(0, 0);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[1].Value = new Point(0, 0);
                    else
                        paukf.KeyFrames[1].Value = new Point(1, 1);
                    daukf.KeyFrames[0].Value = -90;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case RotateDirection.EnterFromRightToTop:
                    paukf.KeyFrames[0].Value = new Point(1, 0);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[1].Value = new Point(1, 0);
                    else
                        paukf.KeyFrames[1].Value = new Point(0, 1);
                    daukf.KeyFrames[0].Value = -90;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case RotateDirection.EnterFromTopToRight:
                    paukf.KeyFrames[0].Value = new Point(1, 0);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[1].Value = new Point(1, 0);
                    else
                        paukf.KeyFrames[1].Value = new Point(0, 1);
                    daukf.KeyFrames[0].Value = 90;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case RotateDirection.EnterFromLeftToBottom:
                    paukf.KeyFrames[0].Value = new Point(0, 1);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[1].Value = new Point(0, 1);
                    else
                        paukf.KeyFrames[1].Value = new Point(1, 0);
                    daukf.KeyFrames[0].Value = -90;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case RotateDirection.EnterFromBottomToLeft:
                    paukf.KeyFrames[0].Value = new Point(0, 1);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[1].Value = new Point(0, 1);
                    else
                        paukf.KeyFrames[1].Value = new Point(1, 0);
                    daukf.KeyFrames[0].Value = 90;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case RotateDirection.EnterFromRightToBottom:
                    paukf.KeyFrames[0].Value = new Point(1, 1);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[1].Value = new Point(1, 1);
                    else
                        paukf.KeyFrames[1].Value = new Point(0, 0);
                    daukf.KeyFrames[0].Value = 90;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case RotateDirection.EnterFromBottomToRight:
                    paukf.KeyFrames[0].Value = new Point(1, 1);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[1].Value = new Point(1, 1);
                    else
                        paukf.KeyFrames[1].Value = new Point(0, 0);
                    daukf.KeyFrames[0].Value = -90;
                    daukf.KeyFrames[1].Value = 0;
                    break;
                case RotateDirection.ExitFromLeftToTop:
                    paukf.KeyFrames[1].Value = new Point(0, 0);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[0].Value = new Point(0, 0);
                    else
                        paukf.KeyFrames[0].Value = new Point(1, 1);
                    daukf.KeyFrames[1].Value = -90;
                    daukf.KeyFrames[0].Value = 0;
                    break;
                case RotateDirection.ExitFromTopToLeft:
                    paukf.KeyFrames[1].Value = new Point(0, 0);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[0].Value = new Point(0, 0);
                    else
                        paukf.KeyFrames[0].Value = new Point(1, 1);
                    daukf.KeyFrames[1].Value = 90;
                    daukf.KeyFrames[0].Value = 0;
                    break;
                case RotateDirection.ExitFromRightToTop:
                    paukf.KeyFrames[1].Value = new Point(1, 0);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[0].Value = new Point(1, 0);
                    else
                        paukf.KeyFrames[0].Value = new Point(0, 1);
                    daukf.KeyFrames[1].Value = 90;
                    daukf.KeyFrames[0].Value = 0;
                    break;
                case RotateDirection.ExitFromTopToRight:
                    paukf.KeyFrames[1].Value = new Point(1, 0);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[0].Value = new Point(1, 0);
                    else
                        paukf.KeyFrames[0].Value = new Point(0, 1);
                    daukf.KeyFrames[1].Value = -90;
                    daukf.KeyFrames[0].Value = 0;
                    break;
                case RotateDirection.ExitFromLeftToBottom:
                    paukf.KeyFrames[1].Value = new Point(0, 1);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[0].Value = new Point(0, 1);
                    else
                        paukf.KeyFrames[0].Value = new Point(1, 0);
                    daukf.KeyFrames[1].Value = 90;
                    daukf.KeyFrames[0].Value = 0;
                    break;
                case RotateDirection.ExitFromBottomToLeft:
                    paukf.KeyFrames[1].Value = new Point(0, 1);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[0].Value = new Point(0, 1);
                    else
                        paukf.KeyFrames[0].Value = new Point(1, 0);
                    daukf.KeyFrames[1].Value = -90;
                    daukf.KeyFrames[0].Value = 0;
                    break;
                case RotateDirection.ExitFromRightToBottom:
                    paukf.KeyFrames[1].Value = new Point(1, 1);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[0].Value = new Point(1, 1);
                    else
                        paukf.KeyFrames[0].Value = new Point(0, 0);
                    daukf.KeyFrames[1].Value = -90;
                    daukf.KeyFrames[0].Value = 0;
                    break;
                case RotateDirection.ExitFromBottomToRight:
                    paukf.KeyFrames[1].Value = new Point(1, 1);
                    if (this.rotateType == RotateType.Direct)
                        paukf.KeyFrames[0].Value = new Point(1, 1);
                    else
                        paukf.KeyFrames[0].Value = new Point(0, 0);
                    daukf.KeyFrames[1].Value = 90;
                    daukf.KeyFrames[0].Value = 0;
                    break;
            }
            this.ImageStoryboard_Rotate.Begin();
        }

        private void ImageStoryboard_Completed(object sender, EventArgs e)
        {
            SetImage(tempSource);
            StopAllStoryBoard();
        }

        /// <summary>
        /// Stop all story board
        /// </summary>
        public void StopAllStoryBoard()
        {
            this.ImageStoryboard_FadeIn.Stop();
            this.ImageStoryboard_Fly.Stop();
            this.ImageStoryboard_Scale.Stop();
            this.ImageStoryboard_Rotate.Stop();
            this.IsRunning = false;
        }

        /// <summary>
        /// Scale direction
        /// </summary>
        private enum ScaleDirection
        {
            /// <summary>
            /// scale from upper left
            /// </summary>
            FromUpperLeft,
            /// <summary>
            /// scale from upper right
            /// </summary>
            FromUpperRight,
            /// <summary>
            /// scale from bottom left
            /// </summary>
            FromBottomLeft,
            /// <summary>
            /// scale from bottom right
            /// </summary>
            FromBottomRight,
            /// <summary>
            /// scale from center
            /// </summary>
            FromCenter,
            /// <summary>
            /// scale from upper left
            /// </summary>
            ToUpperLeft,
            /// <summary>
            /// scale to upper right
            /// </summary>
            ToUpperRight,
            /// <summary>
            /// scale to bottom left
            /// </summary>
            ToBottomLeft,
            /// <summary>
            /// scale to bottom right
            /// </summary>
            ToBottomRight,
            /// <summary>
            /// scale to center
            /// </summary>
            ToCenter
        }

        /// <summary>
        /// Scale type
        /// </summary>
        public enum ScaleType
        {
            /// <summary>
            /// scale directly
            /// </summary>
            Direct,
            /// <summary>
            /// scale with a curve path
            /// </summary>
            Curve
        }

        /// <summary>
        /// Rotate type
        /// </summary>
        public enum RotateType
        {
            /// <summary>
            /// Rotate directly
            /// </summary>
            Direct,
            /// <summary>
            /// Rotate with a curve path
            /// </summary>
            Curve
        }

        /// <summary>
        /// Fly direction
        /// </summary>
        private enum FlyDirection
        {
            /// <summary>
            /// fly in from left
            /// </summary>
            FromLeft,
            /// <summary>
            /// fly in from right
            /// </summary>
            FromRight,
            /// <summary>
            /// fly in from top
            /// </summary>
            FromTop,
            /// <summary>
            /// fly in from bottom
            /// </summary>
            FromBottom,
            /// <summary>
            /// fly out to left
            /// </summary>
            ToLeft,
            /// <summary>
            /// fly out to right
            /// </summary>
            ToRight,
            /// <summary>
            /// fly out to top
            /// </summary>
            ToTop,
            /// <summary>
            /// fly out to bottom
            /// </summary>
            ToBottom
        }

        /// <summary>
        /// Switch type
        /// </summary>
        public enum SwitchType
        {
            /// <summary>
            /// Random
            /// </summary>
            Random = 0,
            /// <summary>
            /// Fade in
            /// </summary>
            FadeIn,
            // -----------------飞入------------------
            /// <summary>
            /// fly in from left
            /// </summary>
            FlyFromLeft,
            /// <summary>
            /// fly in from right
            /// </summary>
            FlyFromRight,
            /// <summary>
            /// fly in from top
            /// </summary>
            FlyFromTop,
            /// <summary>
            /// fly in from bottom
            /// </summary>
            FlyFromBottom,
            //-------------------放大-------------------
            /// <summary>
            /// Scale from upper left
            /// </summary>
            ScaleFromUpperLeft,
            /// <summary>
            /// scale from upper right
            /// </summary>
            ScaleFromUpperRight,
            /// <summary>
            /// scale from bottom left
            /// </summary>
            ScaleFromBottomLeft,
            /// <summary>
            /// scale from bottom right
            /// </summary>
            ScaleFromBottomRight,
            /// <summary>
            /// scale from center
            /// </summary>
            ScaleFromCenter,
            //-------------------旋入-------------------
            /// <summary>
            /// rotate in from left to top
            /// </summary>
            RotateInFromLeftToTop,
            /// <summary>
            /// rotate in from left to bottom
            /// </summary>
            RotateInFromLeftToBottom,
            /// <summary>
            /// rotate in from top to left
            /// </summary>
            RotateInFromTopToLeft,
            /// <summary>
            /// rotate in from top to right
            /// </summary>
            RotateInFromTopToRight,
            /// <summary>
            /// rotate in from right to top
            /// </summary>
            RotateInFromRightToTop,
            /// <summary>
            /// rotate in from right to bottom
            /// </summary>
            RotateInFromRightToBottom,
            /// <summary>
            /// rotate in from bottom to right
            /// </summary>
            RotateInFromBottomToRight,
            /// <summary>
            /// rotate in from bottom to left
            /// </summary>
            RotateInFromBottomToLeft,
            //-----------------------------------------------------------------------------------------------------------------
            //下列都是飞出效果，飞出效果都加到下面，而飞入效果加到上面，添加了飞入飞出效果后记得检查SetImage方法中的判断
            //------------------------------------------------------------------------------------------------------------------
            //
            //--------------------------------飞出--------------------------
            /// <summary>
            /// fly out to left
            /// </summary>
            FlyToLeft,
            /// <summary>
            /// fly out to right
            /// </summary>
            FlyToRight,
            /// <summary>
            /// fly out to top
            /// </summary>
            FlyToTop,
            /// <summary>
            /// fly out to bottom
            /// </summary>
            FlyToBottom,
            //---------------------缩小---------------
            /// <summary>
            /// scale to upper left
            /// </summary>
            ScaleToUpperLeft,
            /// <summary>
            /// scale to upper right
            /// </summary>
            ScaleToUpperRight,
            /// <summary>
            /// scale to bottom left
            /// </summary>
            ScaleToBottomLeft,
            /// <summary>
            /// scale to bottom right
            /// </summary>
            ScaleToBottomRight,
            /// <summary>
            /// scale to center
            /// </summary>
            ScaleToCenter,
            //----------------------旋出--------------------------
            /// <summary>
            /// rotate out from left to top
            /// </summary>
            RotateOutFromLeftToTop,
            /// <summary>
            /// rotate out from left to bottom
            /// </summary>
            RotateOutFromLeftToBottom,
            /// <summary>
            /// rotate out from top to left
            /// </summary>
            RotateOutFromTopToLeft,
            /// <summary>
            /// rotate out from top to right
            /// </summary>
            RotateOutFromTopToRight,
            /// <summary>
            /// rotate out from right to top
            /// </summary>
            RotateOutFromRightToTop,
            /// <summary>
            /// rotate out from right to bottom
            /// </summary>
            RotateOutFromRightToBottom,
            /// <summary>
            /// rotate out from bottom to right
            /// </summary>
            RotateOutFromBottomToRight,
            /// <summary>
            /// rotate out from bottom to left
            /// </summary>
            RotateOutFromBottomToLeft
        }

        /// <summary>
        /// Rotate direction
        /// </summary>
        private enum RotateDirection
        {
            /// <summary>
            /// rotate in from left to top
            /// </summary>
            EnterFromLeftToTop,
            /// <summary>
            /// rotate in from left to bottom
            /// </summary>
            EnterFromLeftToBottom,
            /// <summary>
            /// rotate in from right to top
            /// </summary>
            EnterFromRightToTop,
            /// <summary>
            /// rotate in from right to bottom
            /// </summary>
            EnterFromRightToBottom,
            /// <summary>
            /// rotate in from top to left
            /// </summary>
            EnterFromTopToLeft,
            /// <summary>
            /// rotate in from top to right
            /// </summary>
            EnterFromTopToRight,
            /// <summary>
            /// rotate in from bottom to left
            /// </summary>
            EnterFromBottomToLeft,
            /// <summary>
            /// rotate in from bottom to right
            /// </summary>
            EnterFromBottomToRight,
            /// <summary>
            /// rotate out from left to top
            /// </summary>
            ExitFromLeftToTop,
            /// <summary>
            /// rotate out from left to bottom
            /// </summary>
            ExitFromLeftToBottom,
            /// <summary>
            /// rotate out from right to top
            /// </summary>
            ExitFromRightToTop,
            /// <summary>
            /// rotate out from right to bottom
            /// </summary>
            ExitFromRightToBottom,
            /// <summary>
            /// rotate out from top to left
            /// </summary>
            ExitFromTopToLeft,
            /// <summary>
            /// rotate out from top to right
            /// </summary>
            ExitFromTopToRight,
            /// <summary>
            /// rotate out from bottom to left
            /// </summary>
            ExitFromBottomToLeft,
            /// <summary>
            /// rotate out from bottom to right
            /// </summary>
            ExitFromBottomToRight
        }
    }
}
